Total Complexity | 2 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
9 | |||
10 | @QueryHandler(GetEventByIdQuery) |
||
11 | export class GetEventByIdQueryHandler { |
||
12 | constructor( |
||
13 | @Inject('IEventRepository') |
||
14 | private readonly eventRepository: IEventRepository |
||
15 | ) {} |
||
16 | |||
17 | public async execute({ id }: GetEventByIdQuery): Promise<EventDetailView> { |
||
18 | const event = await this.eventRepository.findOneById(id); |
||
19 | if (!event) { |
||
20 | throw new EventNotFoundException(); |
||
21 | } |
||
22 | |||
23 | const school = event.getSchool(); |
||
24 | const user = event.getPhotographer(); |
||
25 | |||
26 | return new EventDetailView( |
||
27 | event.getId(), |
||
28 | new SchoolSummaryView( |
||
29 | school.getId(), |
||
30 | school.getName(), |
||
31 | school.getReference(), |
||
32 | school.getAddress(), |
||
33 | school.getCity(), |
||
34 | school.getZipCode(), |
||
35 | ), |
||
36 | new UserSummaryView( |
||
37 | user.getId(), |
||
38 | user.getFirstName(), |
||
39 | user.getLastName(), |
||
40 | user.getEmail(), |
||
41 | ), |
||
42 | event.getDate(), |
||
43 | event.getSummary() |
||
44 | ); |
||
47 |